<%@page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!-- public quote -->
<%@include file="/jsp/comm_css_include.jsp"%>
<!-- jqgrid-->
<link
	href="${basePath}/css/plugins/jqgriddemo/css/ui.jqgrid-bootstrap.min.css"
	rel="stylesheet" />
<!doctype html>
<html>
<head>
</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="iboxtitle">
			<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;贷中业务>合同套打</span>
		</div>
		<div class="ibox-content ibox-zxsearchqu">
			<div class="row">
				<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
					<div class="col-xs-12 col-sm-4 col-md-4 col-lg-2">
						 <input type="text" placeholder="客户名" id="customerName" name="customerName" class="form-control">
					</div>
					<div class="col-xs-12 col-sm-4 col-md-4 col-lg-2">
						 <input type="text" placeholder="身份证号" id="customerNo" name="customerNo" class="form-control">
					</div>
					<div class="col-xs-12 col-sm-4 col-md-4 col-lg-2">
						<button class="zhixcx" type="button" onclick="query();">执行查询</button>
					</div>
				</div>	
			</div>	
			
		</div>
		<div class="ibox-content">
			<span class="warning-label"><span class="red-dp-circle"></span>完成车辆资料复审的订单信息</span>	
			<div class="jqGrid_wrapper">
				<table id="table_list_1"></table>
				<div id="pager_list_1"></div>
			</div>
		</div>
	</div>

	<div class="ibox-content" id="hetongtaoda" style="display: none;">
		<form class="form-horizontal" id="commentForm">
			<table cellpadding="0" cellspacing="0" border="0" class="infor-table">
				<tr>
					<td align="right" valign="top">
						<label class="control-label np">可选合同号前缀：</label>
						<input id="busiID" value=""  type="hidden" />
					<td>
						<table class="hetongver" id="hetongver"></table>
					</td>
				</tr>
			</table>
		</form>
		<table cellpadding="0" cellspacing="0" border="0" bordercolor="#3B95C8"  width="100%" style="margin-top: 20px;">
			<tr>
				<td width="100%" align="center">
					<div class="ibox-content">
						  <button type="button" class="btn dpbtn_green" id="taoda" onclick="taodaht('+busiId+')">套打</button>
						  <button type="button" class="btn dpbtn_red" onclick="cancel();">取消</button>
					</div>
			   </td>
			</tr>
		</table>
	</div>
	<!-- public quote -->
	<%@include file="/jsp/comm_js_include.jsp"%>

	<!-- jqGrid -->
	<script type="text/javascript" charset="utf-8" src="${basePath}/js/plugins/jqgriddemo/js/jquery.jqGrid.min.js"></script>
	<script type="text/javascript" charset="utf-8" src="${basePath}/js/plugins/jqgriddemo/js/grid.locale-cn.min.js"></script>

	<!-- 
    	描述：js
    -->
	<script type="text/javascript">
		var busiId;
	    jQuery(function($) {  
	    	getData();
	    });
	    
	    var getContractDicList=function(cartype){
	    	$.dpAjax({
	    		url:'${basePath}/DataDictionaryController/getEnableList',
	 			data:{
	 				"parentValue":"CarContractType",
	 				"addedValue2":cartype 
	 			},
    			success: function(datas){
					  var data=datas.result.rows;
					  if(data.length>0){
						  var html="";
						  html+='<tr><td><label><input type="radio" checked="checked" name="hetong" value=""/>留空</label></td></tr>';
						  for(var i=0;i<data.length;i++){
							  if(data.addedValue2 != ""){
								  html+='<tr><td><label><input type="radio" name="hetong" value="'+data[i].value+'"/>'+data[i].name+'</label></td></tr>';  
							  }
						  }
						  document.getElementById("hetongver").innerHTML=html;
					  }
                 }
	    	});
	    } 
	    var getData = function()
	    {
	  var winWidth = $('div.ibox-content').width();
	        var winHeight = document.body.offsetHeight - 330;
	     	var win = winWidth / 10;
  	 	   $.jgrid.defaults.styleUI = 'Bootstrap';
		  jQuery("#table_list_1").jqGrid
		  ({
			url:'${basePath}/ContractbindingController/mulitList',
	        datatype : "json",
	        colNames : [ '主键','','','','垫款时间','车辆类型', '客户姓名', '身份证号码','签约贷款额', '订单类型', '经销商','经销商等级', '部门','业务员',  '银行','业务编码','贷款银行code','业务状态'],
	        colModel : [ 
	                     {name: 'replaceId', index: 'id', hidden:true},
	                     {name: 'busiId', index: 'busiId', hidden:true},
	                     {name:'operate',index:'operate',align: "left",width: 80,align: "center",formatter: function (value, grid, rows, state) { 
	            			 var html1='<button class="btn btn-success" onclick="downloadContrcat(\''+ rows.replaceId + '\',\''+ rows.bankLoan + '\',\''+ rows.carType + '\');">打印</button>';
            					 return html1;
	            			} 	
	            		 },
	            		 {name: 'timeContractPrint',index: 'timeContractPrint',width: 80,align: "center",formatter: function (value, grid, rows, state) { 
	            			 var html2='';
	            			 if(rows.timeContractPrint==null){
			            		 html2='&nbsp;<button class="btn btn-danger"  onclick="confirmContract(\''+ rows.replaceId + '\');">提交</button>';
			            		 return html2;
	            			 }
	            			 if(rows.timeContractPrint!=null){
		            			 html2='-';
		            			 return html2;
		            		 }
	            			} 	
	            		 },
	                     {name: 'loanTime',index: 'loanTime',width: 170,align: "center"},
	                     {name: 'carTypeDisplay',index: 'carType',width: 130,align: "center"},
	            		 {name: 'customerName',index: 'customerName',width: 130,align: "center"},
	            		 {name: 'customerNo',index: 'customerNo',width: 170,align: "center"},
	            		 {name: 'signLoanAmount',index: 'signLoanAmount',width: 100,align: "center"},
	                  	 {name: 'channelTypeDisplay',index: 'channelType',width: 100,align: "center"},
	               		 {name: 'dealerName',index: 'dealerName',width: 300,align: "center"},
	               		 {name: 'dealerLevel',index: 'dealerLevel',width: 100,align: "center"},
	            		 {name: 'orgName',index: 'orgName',width: win,align: "center"},
	            		 {name: 'salesmanName',index: 'salesmanName',width: 100,align: "center"},
	            		 {name: 'bankLoanDisplay',index: 'bankLoan',width:300,align: "center"},
	            		 {name: 'busiCode', index: 'busiCode', hidden:true},
	            		 {name: 'bankLoan', index: 'bankLoan', hidden:true},
	            		 {name: 'busiStatus', index: 'busiStatus', hidden:true}
	                   ],
              mtype : "post",
              height: winHeight,
              width:winWidth,  
              autowidth: false,
              shrinkToFit: false,
              rowNum: 15,
	          rowList: [15, 30, 45],
              viewrecords: true,
              pager: "#pager_list_1",
              hidegrid: false,
              multiselect : false,
              altRows:true,
              altclass:'someClass',
              jsonReader : {
            	  root:"result.rows",
            	  page: "result.page",
            	  total: "result.total",
            	  records: "result.records",
            	  repeatitems: false,
            	  id: "replaceId"
              },
              loadComplete:function(datas){
            	  if (datas.flag == "100100") {
                      layer.msg("查询成功!", {icon: 6, time: 1000});
                      return;
                  }
            	  if(datas.flag == '100802') {
    				  top.location.href = thisLoginUrl;
    				  return;
    			  }

            	  layer.msg(datas.message, {icon: 2});
              }
	      });
	    }	  
	    
	    var updateLayer;
	    
	    window.onresize = function()
	    {
	    	$("#table_list_1").setGridWidth($(window).width()-80);
	    }
	    //打印
	    var downloadContrcat=function(busiId,type,cartype){
	    	 $.dpAjax({
	  	    		url:'${basePath}/ContractbindingController/checkLoanEditLock',
	  	    		data:{"busiId":busiId},
	  				success: function(datas){
	  	    			  if(datas.flag == "100100")
	  					  {
	  	    				if(type == "ICBC"){
	  	    		    		 $("#busiID").val(busiId);
	  	    		    		 getContractDicList(cartype);
	  	    		    		 taodalayer();
	  	    				}else{
	  	    					window.location.href="${basePath}/ContractbindingController/download?prefix=null&busiId="+busiId+"&bank="+type;
	  	    					layer.msg("合同套打中!", {icon: 6});
	  	    				}
	  						  return;
	  					  }
	  					  if(datas.flag == "100200")
	  	                  {
	  						  $.fn.showDatas({"datas":datas});
	  	                	  return;
	  	                  }
	  	            }
	  	    	});
	    	
	    	 
	    	
	    }
	    
	    function taodalayer(){
	    	updateLayer =  layer.open({
		    	  type: 1,
		    	  title: '选择合同号',
		    	  shadeClose: true,
		    	  area: ['400px', '400px'],
		    	  content: $('#hetongtaoda'),
		    	  end: function () 
		    	  {
		    		  refresh();
		          }
	    		});  
	    }
	    
	    function taodaht(){
	    	var busiId = $("#busiID").val();
	    	var prefix=$("input[name='hetong']:checked").val();
	    	if(typeof(prefix) != "undefined"){
	    		 $.dpAjax({
	   	    		url:'${basePath}/ContractbindingController/checkLoanEditLock',
	   	    		data:{"busiId":busiId},
	   				success: function(datas){
	   					if(datas.result){
	   						window.location.href="${basePath}/ContractbindingController/download?prefix="+prefix+"&busiId="+busiId+"&bank=ICBC";
	   		 	    	 	layer.close(updateLayer);
	   		    		 	layer.msg("合同套打中!", {icon: 6});
	   					}else{
	   						layer.msg(datas.message, {icon: 5});
	   					}
	   				}
	    		 });
	    	 }
	    }
	    
	    
	    //提交
	    var confirmContract=function(busiId){
	    	layer.confirm('是否提交合同套打？', {
                btn: ['确定','取消'] //按钮
          },function(){
        	  layer.closeAll();
        	  $.dpAjax({
  	    		url:'${basePath}/ContractbindingController/confirmContract',
  	    		data:{"busiId":busiId},
  				success: function(datas){
  	    			  if(datas.flag == "100100")
  					  {
  	    				  refresh();
  						  return;
  					  }
  					  if(datas.flag == "100200")
  	                  {
  						  $.fn.showDatas({"datas":datas});
  	                	  return;
  	                  }
  	            }
  	    	});
          })
	    }
	    var query = function(dayEnum)
	    {
	    	var postData = $("#table_list_1").jqGrid("getGridParam", "postData");
	    	var data = {};
	    	data.customerName = document.getElementById('customerName').value || '';
	    	data.customerNo = document.getElementById('customerNo').value || '';
	    	$.extend(postData, data);
	    	refresh();
	    }
	    
	    var refresh = function()
	    {
	    	$("#table_list_1").jqGrid("setGridParam", { search: true }).trigger("reloadGrid", [{ page: 1}]);
	    }
	    
	    var cancel= function(){
	    	layer.closeAll();
	    }
    </script>
</body>
</html>
